import config from "@/config"
import http from "@/utils/request"


export default {
    list: {
        url: `${config.API_URL}/dict-words/list-page`,
        name: "获取列表",
        get: async function (params) {
            return await http.get(this.url, params);
        }
    },
	import: {
		url: `${config.API_URL}/dict-words/import`,
		name: "词汇导入",
		post: async function (params) {
			return await http.post(this.url, params);
		},
	},
    action: {
        url: `${config.API_URL}/dict-words`,
        name: "用户操作",
        get: async function (params) {
            return await http.get(this.url, params);
        },
        post: async function (params) {
            return await http.post(this.url, params);
        },
        put: async function (params) {
            return await http.put(this.url, params);
        },
        save: async function (param) {
            if (param.id) {
                return await http.put(this.url, param);
            } else {
                return await http.post(this.url, param);
            }
        },
        delete: async function (params) {
            return await http.delete(this.url, params);
        }
    },
    getWord: {
        url: `${config.API_URL}/dict-words/word`,
        name: "获取词汇",
        get: async function (params) {
            return await http.get(this.url, params);
        }
    },
	definitions: {
        list: {
            url: `${config.API_URL}/dict-concise-oald-definitions/list-page`,
            name: "获取列表",
            get: async function (params) {
                return await http.get(this.url, params);
            }
        },
		import: {
			url: `${config.API_URL}/dict-concise-oald-definitions/import`,
			name: "释义例句导入",
			post: async function (params) {
				return await http.post(this.url, params);
			},
		},
        all: {
            url: `${config.API_URL}/dict-concise-oald-definitions/all`,
            name: "获取所有",
            get: async function (params) {
                return await http.get(this.url, params);
            }
        },
        action: {
            url: `${config.API_URL}/dict-concise-oald-definitions`,
            name: "用户操作",
			get: async function (params) {
				return await http.get(this.url, params);
			},
            post: async function (params) {
                return await http.post(this.url, params);
            },
            put: async function (params) {
                return await http.put(this.url, params);
            },
            delete: async function (params) {
                return await http.delete(this.url, params);
            }
        }
    },
    examples: {
        list: {
            url: `${config.API_URL}/dict-words-examples/list-page`,
            name: "获取列表",
            get: async function (params) {
                return await http.get(this.url, params);
            }
        },
        action: {
            url: `${config.API_URL}/dict-words-examples`,
            name: "用户操作",
			get: async function (params) {
				return await http.get(this.url, params);
			},
            post: async function (params) {
                return await http.post(this.url, params);
            },
            put: async function (params) {
                return await http.put(this.url, params);
            },
            save: async function (param) {
                if (param.id) {
                    return await http.put(this.url, param);
                } else {
                    return await http.post(this.url, param);
                }
            },
            delete: async function (params) {
                return await http.delete(this.url, params);
            }
        }
    },
}

/**
 * 保存
 * @param {array} param
 * @returns
 */
export function saveWordExample(param) {
	return new Promise((resolve, reject) => {
		if (param.id) {
			http.put(`${config.API_URL}/dict-words-examples`, param).then(res => {
				resolve(res.data)
			}).catch(error => {
				reject(error)
			})
		} else {
			http.post(`${config.API_URL}/dict-words-examples`, param).then(res => {
				resolve(res.data)
			}).catch(error => {
				reject(error)
			})
		}
	})
}